/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.address;

import junit.framework.TestCase;

import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class MailtoURIImplTest extends TestCase {
    public MailtoURIImplTest(String name) {
        super(name);
    }

    public void testSimpleCreation() {
        MailtoURIImpl uri = new MailtoURIImpl();
        assertEquals("The scheme is wrong!", "mailto", uri.getScheme());
        assertNull("The user is not null!", uri.getUser());
        assertNull("The host is not null!", uri.getHost());
    }

    public void testToString() {
        final String USER = "alice";
        final String HOST = "yahoo.com";
        MailtoURIImpl uri = new MailtoURIImpl(USER, HOST);
        try {
            uri.setParameter("custom", "mine");
        } catch (ParseException e) {
            fail("Cannot set parameter for the URI: " + e.getMessage());
        }
        try {
            uri.setHeader("priority", "urgent");
        } catch (ParseException e) {
            fail("Cannot set header for the URI: " + e.getMessage());
        }
        assertEquals("The string form of the URI is wrong!", "mailto:alice@yahoo.com", uri.toString());
    }

    public void testLazyCreation() {
        final byte[] bytes = "mailto:alice@yahoo.com".getBytes();
        final MailtoURIImpl uri = MailtoURIImpl.createLazily(bytes, 0, bytes.length);
        assertEquals("The scheme is wrong!", "mailto", uri.getScheme());
        assertFalse("The URI must not be SIP!", uri.isSipURI());
        assertEquals("The user is wrong!", "alice", uri.getUser());
        assertEquals("The host is wrong!", "yahoo.com", uri.getHost());
    }

    public void testClone() {
        final byte[] bytes = "mailto:alice@yahoo.com".getBytes();
        final MailtoURIImpl uri = MailtoURIImpl.createLazily(bytes, 0, bytes.length);
        final MailtoURIImpl newUri;
        try {
            newUri = (MailtoURIImpl) uri.clone();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Cannot clone the URI object: " + e);
            return;
        }
        assertEquals("The URI objects are not equal!", newUri, uri);
        assertEquals("The schemas are not equal!", newUri.getScheme(), uri.getScheme());
        assertEquals("The users are not equal!", newUri.getUser(), uri.getUser());
        assertEquals("The hosts are not equal!", newUri.getHost(), uri.getHost());
    }
}
/*
 * $Log$
 */